package com.zyt.i18n.controller;

import com.zyt.i18n.annotation.I18n;
import com.zyt.i18n.model.Merchant;
import com.zyt.i18n.model.Shop;
import com.zyt.i18n.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;


/**
 * 功能描述
 * @author zhang_yt@suixingfu.com
 * @date   2018/12/21
 * @param   * @param null
 * @return
 */
@I18n("dashboard")
@Controller
@RequestMapping("dashboard")
public class DashboardController {

    @Autowired
    private MessageSource messageSource;

    //@I18n("dashboard")  可以把注解加到此处
    @GetMapping
    public String dashboard(Model model) {
        List<Merchant> merchants = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Merchant merchant = new Merchant();
            merchants.add(merchant);
        }
        List<Shop> shops = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            Shop shop = new Shop();
            shops.add(shop);
        }
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            User user = new User();
            users.add(user);
        }
        model.addAttribute("merchants", merchants);
        model.addAttribute("shops", shops);
        model.addAttribute("users", users);

        Locale locale = LocaleContextHolder.getLocale();

        model.addAttribute("world", messageSource.getMessage("world", null, locale));
        return "system/dashboard";
    }

}
